<%--
/*
 * ============================================================================
 * GNU Lesser General Public License
 * ============================================================================
 *
 * JasperReports - Free Java report-generating library.
 * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
 * 
 * JasperSoft Corporation
 * 303 Second Street, Suite 450 North
 * San Francisco, CA 94107
 * http://www.jaspersoft.com
 */
--%>

<%@ page import="net.sf.jasperreports.engine.*" %>
<%@ page import="net.sf.jasperreports.engine.util.*" %>
<%@ page import="net.sf.jasperreports.engine.export.*" %>
<%@ page import="net.sf.jasperreports.j2ee.servlets.*" %>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.text.DateFormat" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="net.sf.jasperreports.view.JasperViewer" %>

<%
        DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");

        ServletContext context = this.getServletConfig().getServletContext();

        String reportSource = context.getRealPath("report/templates/AuditoriaAcceso.jrxml");

        Map<String, Object> params = new HashMap<String, Object>();
        params.put("author", "Juan Marcelo Ferreira");
        try {
            params.put("fdesde", dateFormat.parse("06/06/2008"));
            params.put("fhasta", dateFormat.parse("06/06/2008"));
        } catch (Exception e) {
            e.printStackTrace();
            out.println(e.toString());
        }
        try {

            JasperReport jasperReport = JasperCompileManager.compileReport(reportSource);
            //JasperCompileManager.compileReportToFile(reportSource);
            // Make the driver class available.
            Class.forName("org.postgresql.Driver");

            // Create a connection to pass into the report.
            java.sql.Connection conn = DriverManager.getConnection(
                    "jdbc:postgresql://localhost:5432/srr", "postgres", "postgres");

            JasperPrint jasperPrint =
                    JasperFillManager.fillReport(
                    jasperReport,
                    params,
                    conn);

           JasperViewer.viewReport(jasperPrint,false);
            
/*
            JRHtmlExporter exporter = new JRHtmlExporter();
            StringBuffer sbuffer = new StringBuffer();

            exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
            exporter.setParameter(JRExporterParameter.OUTPUT_WRITER, out);
            exporter.setParameter(JRHtmlExporterParameter.IMAGES_URI, "http://localhost:8080/sistemaReserva/faces/images/");

            exporter.exportReport();
 */
            out.println("REPORTE GENERADO EXITOSAMENTE");
            
        } catch (JRException e) {
            e.printStackTrace();
            out.println(e.toString());

        } // Exception handling for the Class.forName method.
        catch (ClassNotFoundException ex) {
            ex.printStackTrace();
            out.println(ex.toString());

        } // Exception handling for the DriverManager.getConnection method.
        catch (SQLException ex) {
            ex.printStackTrace();
            out.println(ex.toString());

        }

%>

